package com.ccs.demo.controller;


import com.ccs.demo.constant.Constants;
import com.ccs.demo.service.UserService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.HandlerInterceptor;

import java.nio.charset.StandardCharsets;

@RestController
@RequestMapping("/user")
public class UserController implements HandlerInterceptor {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
        public Boolean login(String username, String password,HttpSession session) {
        if(!StringUtils.hasLength(username) && !StringUtils.hasLength(password)){
            return false;
        }
//        //固定值
//        if("admin".equals(name) && "admin".equals(password)){
//            session.setAttribute("name",name);
//            return true;
//        }
        //连接数据库 校验账号密码是否正确
        Boolean result=userService.checkPassword(username,password);
        if(result){
            session.setAttribute("username",username);
        }
        return result;
    }



}
